package com.qilu.pe.ui.activity;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.androidkun.xtablayout.XTabLayout;
import com.qilu.pe.R;
import com.qilu.pe.base.Base2Activity;
import com.qilu.pe.support.util.ActiviceCollector;
import com.qilu.pe.ui.fragment.MyProduct1Fragment;

// 我的商品
public class MyProductActivity extends Base2Activity {
    private XTabLayout tab_2;
    private ViewPager vp_tab;

    private static final String[] HOME_MODELS = {"全部", "待付款", "已付款", "已发货", "已取消"};
    private MyProductAdapter vpTabAdapter;

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_my_product;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActiviceCollector.addActivity(this);
        tab_2 = findViewById(R.id.tab_2);
        vp_tab = findViewById(R.id.vp_tab);

        setHeadTitle("我的商品");

        vpTabAdapter = new MyProductAdapter(getSupportFragmentManager());
        vp_tab.setAdapter(vpTabAdapter);
        tab_2.setupWithViewPager(vp_tab);
        vp_tab.setOffscreenPageLimit(9);
    }

    private class MyProductAdapter extends FragmentPagerAdapter {

        public MyProductAdapter(@NonNull FragmentManager fm) {
            super(fm);
        }

        @NonNull
        @Override
        public Fragment getItem(int position) {
            // 0待付款,1未发货,2已付款,3已发货  页面:全部 待付款 已付款
            // 0待付款,1未发货,2已付款,3已发货,4已收货,5退款中,6取消订单
            if (position == 0) {
                return MyProduct1Fragment.newInstance("");
            } else if (position == 1) {
                return MyProduct1Fragment.newInstance("0");
            } else if (position == 2) {
                return MyProduct1Fragment.newInstance("2");
            } else if (position == 3) {
                return MyProduct1Fragment.newInstance("3");
            } else if (position == 4) {
                return MyProduct1Fragment.newInstance("6");
            }
            return MyProduct1Fragment.newInstance("");
        }

        @Override
        public int getCount() {
            return 5;
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return HOME_MODELS[position];
        }
    }
}